//
//  search_userNameCell.m
//  SoundPill
//
//  Created by 宋鹏鹏 on 15/4/8.
//  Copyright (c) 2015年 宋旭东. All rights reserved.
//

#import "search_userNameCell.h"
#include "AFNetworking.h"
//#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
#import "SDWebImageManager.h"
#define kleftGap  16
#define kupGap   12
#define kDeviceWidth [UIScreen mainScreen].bounds.size.width
#define kImageViewWidth 40
#define kImageViewHeight 40
#define kLabelWidth [UIScreen mainScreen].bounds.size.width - 100
#define kLabelHeight 40

@implementation search_userNameCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubViews];
        
        //self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.backgroundColor=[UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return self;
}

- (void)initSubViews
{
    // 图片
    _headImage = [[UIButton alloc] initWithFrame:CGRectZero];
    [self.contentView addSubview:_headImage];
    
    // 名字
    _personName = [[UILabel alloc] initWithFrame:CGRectZero];
    _personName.backgroundColor = [UIColor whiteColor];
    _personName.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:_personName];
    
    button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:button];
}



- (void)layoutSubviews
{
    [super layoutSubviews];
    //首图预览
    _headImage.frame = CGRectMake(kleftGap, kupGap, self.frame.size.height - 2 * kupGap, self.frame.size.height - 2 * kupGap);
    _headImage.backgroundColor=[UIColor whiteColor];
    [_headImage setBackgroundImageWithURL:[NSURL URLWithString:_plazadataModel.headImageURL] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"default_head"]];
    
    if (self.plazadataModel.headImageURL.length<1) {
        [_headImage setBackgroundImage:[UIImage imageNamed:@"default_head"] forState:UIControlStateNormal];
    }
    
    //分隔线
    UIView *downDivider = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.frame.size.height, kDeviceWidth, 1)];
    downDivider.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"gray_line"]];
    
    [self.contentView addSubview:downDivider];
    
    // 名字
     _personName.frame = CGRectMake(_headImage.right+10, 10, kLabelWidth, kLabelHeight);
    _personName.center = CGPointMake(_personName.center.x, _headImage.center.y);
    //_personName.text=@"犀牛哥要peace";
    _personName.text= self.plazadataModel.personName;
    
    
    button.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    [button addTarget:self action:@selector(userHeadClick) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)userHeadClick
{
//    //发通知
//    NSDictionary *dict =[[NSDictionary alloc] initWithObjectsAndKeys:self.plazadataModel.CinemeID,@"textOne", nil];
//    //创建通知
//    NSNotification *notification =[NSNotification notificationWithName:@"worksHeadClick" object:nil userInfo:dict];
//    //通过通知中心发送通知
//    [[NSNotificationCenter defaultCenter] postNotification:notification];
    
//    NSUserDefaults *userDefaultes = [NSUserDefaults standardUserDefaults];
//    [userDefaultes setObject:self.plazadataModel.CinemeID forKey:@"othersUserID"];
//    [userDefaultes synchronize];
    
    
    if ([self.searchPushDelegate respondsToSelector:@selector(searchHeadPush:)]) {
        [self.searchPushDelegate searchHeadPush:self.plazadataModel.CinemeID];
    }


}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
